/*
 * Copyright 2007 Sam Hough
 * 
 * This file is part of GWTS.
 *
 * GWTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * GWTS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GWTS.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.redspr.gwts;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GWTSServlet extends HttpServlet {
    private final static String KEY = "tryst";

    public GWTSServlet() {
    }

    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        // "file:///C:/Documents and Settings/sam/Desktop/test.html";
        Tryst tryst = (Tryst) req.getSession().getAttribute(KEY);
        if (tryst == null) {
            try {
                String pfx = "file:///C:/psrc/gwt/build/out/samples/";
                String ks = pfx
                        + "KitchenSink/www/com.google.gwt.sample.kitchensink.KitchenSink/KitchenSink.html";
                String dt = pfx
                        + "DynaTable/www/com.google.gwt.sample.dynatable.DynaTable/DynaTable.html";
                String m = pfx
                        + "Mail/www/com.google.gwt.sample.mail.Mail/Mail.html";
                String h = pfx
                        + "Hello/www/com.google.gwt.sample.hello.Hello/Hello.html";
                String ut = "file:///C:/Documents and Settings/sam/Desktop/testa.html";
// TODO 00 from config
                tryst = new Tryst(
                        "http://gwt.google.com/samples/Mail/Mail.html");
                req.getSession().setAttribute(KEY, tryst);
            } catch (Exception ex) {
                throw new ServletException(ex);
            }
        }

        if ("/".equals(req.getRequestURI())) {
            res.setContentType("text/html");
            tryst.click(req, res);
        } else {
            // TODO 00 should log unwanted request
        }
    }

    @Override
    public void init() throws ServletException {
        super.init();
    }
}
